<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        #date{width:400px;height:300px;background:#fac;margin:50px auto;}
        .tb{width:400px;height:300px;text-align: center;}

    </style>
    <script type="text/javascript">
        var weeks=["周日","周一","周二","周三","周四","周五","周六"];
        var months=[1,2,3,4,5,6,7,8,9,10,11,12];
        var days=[31,28,31,30,31,30,31,31,30,31,30,31];
        var date=new Date();
        var currentDay=date.getDate();//当前日期
        var year=date.getFullYear();
        var month=date.getMonth();
        date.setDate(1);
        var week=date.getDay();
        var monthDays;//
        var rows=Math.floor((week+days[month]+6)/7);//行数,找规律
        var yearFlag=0;
        var f=1;
        if((year%4==0&&year%100!=0)||(year%400==0))
        {
            yearFlag=1;
        }
        else
        {
            yearFlag=0;
        }
        if(month==1)//二月份
        {
            monthDays=days[month]+yearFlag;
        }else
        {
            monthDays=days[month];
        }

        document.write('<div id="date"><table class="tb">');
        document.write('<tr>');
        for(var index in weeks)
        {
            document.write("<th>"+weeks[index]+"</th>")
        }

     for(var i=0;i<rows;i++)
        {
            document.write("<tr>");
            for(var j=0;j<7;j++)
          {
              if(i==0&&j<week)
              {
                  document.write("<td>")
              }
              else
              {
                  if(f>monthDays)
                  {
                      break;
                  }
                  document.write("<td id="+f+">"+f);
                  if(f==currentDay)
                  {
                      document.getElementById(f).style.backgroundColor="red";
                  }

                  f++;

              }
              document.write("</td>")
            }
            document.write("</tr>")
        }

        document.write('</table></div>');

    </script>
</head>
<body>

</body>
</html>